#ifndef _PLATFORM_CQFM3DUINO_SELECTOR_H_
#define _PLATFORM_CQFM3DUINO_SELECTOR_H_ 1

/////////////////////////////////////////////////////////
//
// processor and features
//

#if defined(PLATFORM_ARM_CQFM3DUINO)
#define HAL_SYSTEM_NAME                     "CQFM3DUINO"

#define CQFM3DUINO
#define MB9BF618T
//#define EXRAM
#define USB_ALLOW_CONFIGURATION_OVERRIDE  1
#define OPENSSL_SYS_ARM
//#define HAL_REDUCESIZE
//#define USB_DEBUG


//
// processor and features
//
/////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////
//
// constants
//

// HCLK 144MHz
// PCLK0 72Mhz
// PCLK1 72Mhz
// PCLK2 72MHz
// SLOW_CLOCKS_PER_SECOND = PCLK/(WCRL <- 0x28 = 40) = 1000000Hz
#define SYSTEM_CLOCK_HZ					144000000		// HCLK = 144MHz
#define SYSTEM_CYCLE_CLOCK_HZ			144000000		// HCLK = 144MHz (1 instruction clock)
#define PCLK							72000000		// PCLK = HCLK/2, APB0 CLOCK
#define PCLK2							72000000		// PCLK2 = HCLK/2, APB2 CLOCK
#define CLKDEV							16				// 16, 256
#define SLOW_CLOCKS_PER_SECOND			(SYSTEM_CLOCK_HZ/CLKDEV)	// 144MZ/16
#define CLOCK_COMMON_FACTOR				100000			// GCD(SYSTEM_CLOCK_HZ, 1M)
#define SLOW_CLOCKS_TEN_MHZ_GCD			10000   		// GCD(SLOW_CLOCKS_PER_SECOND, 10M)
#define SLOW_CLOCKS_MILLISECOND_GCD		100			// GCD(SLOW_CLOCKS_PER_SECOND, 1k)

#define FLASH_MEMORY_Base	0x00000000
#define FLASH_MEMORY_Size	0x00100000
#ifndef EXRAM
#define SRAM1_MEMORY_Base	0x1FFF0000
#define SRAM1_MEMORY_Size	0x00020000
#else
#define SRAM1_MEMORY_Base	0x60000000
#define SRAM1_MEMORY_Size	0x00400000
#endif

#define TXPROTECTRESISTOR				RESISTOR_DISABLED
#define RXPROTECTRESISTOR				RESISTOR_DISABLED
#define CTSPROTECTRESISTOR				RESISTOR_DISABLED
#define RTSPROTECTRESISTOR				RESISTOR_DISABLED

#define INSTRUMENTATION_H_GPIO_PIN		GPIO_PIN_NONE

#define TOTAL_USART_PORT				3
#define COM1						ConvertCOM_ComHandle(0)
#define COM2						ConvertCOM_ComHandle(1)
#define COM3						ConvertCOM_ComHandle(2)
#define USART_DEFAULT_PORT				COM1
#define USART_DEFAULT_BAUDRATE			115200

#define TOTAL_USB_CONTROLLER		1
#define USB1						ConvertCOM_UsbHandle(0)

#define USB_IRQ_INDEX               34  // TODO set right index

#define PLATFORM_DEPENDENT_TX_USART_BUFFER_SIZE    128  // there is one TX for each usart port
#define PLATFORM_DEPENDENT_RX_USART_BUFFER_SIZE    256  // there is one RX for each usart port
#define PLATFORM_DEPENDENT_USB_QUEUE_PACKET_COUNT  2    // there is one queue for each pipe of each endpoint and the size of a single packet is sizeof(USB_PACKET64) == 68 bytes

#if 0
#define DEBUG_TEXT_PORT		COM1
#define STDIO				COM1
#define DEBUGGER_PORT		COM1
#define MESSAGING_PORT		COM1
#else
#define DEBUG_TEXT_PORT		USB1
#define STDIO				USB1
#define DEBUGGER_PORT		USB1
#define MESSAGING_PORT		USB1
#endif

#define FM3_USE_I2C2		1

#define FM3_USB_Attach_Pin_Low        (16 + 14) // B14

//#define DRIVER_PAL_BUTTON_MAPPING                  \
//    { 11 * 16 +  7, BUTTON_B0 }, /* PB7: Up */      \
//    { 11 * 16 +  6, BUTTON_B1 }, /* PB6: Down */    \
//    { 11 * 16 +  5, BUTTON_B2 }, /* PB5: Left */    \
//    { 11 * 16 +  4, BUTTON_B3 }, /* PB4: Right */   \
//    {  3 * 16 + 13, BUTTON_B4 }, /* P3D: Enter */   \
//    {  0 * 16 +  9, BUTTON_B5 }, /* P09: User */

//
// CLR runtime memory configuration
//
#define RUNTIME_MEMORY_PROFILE__extrasmall	1

#define NETWORK_INTERFACE_COUNT				1
#define NETWORK_MEMORY_PROFILE__small		1
#define NETWORK_MEMORY_POOL__INCLUDE_SSL    1
#include <pal\net\Network_Defines_lwip.h>
//
// constants
/////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////
//
// macros
//

#define GLOBAL_LOCK(x)             SmartPtr_IRQ x
#define DISABLE_INTERRUPTS()       SmartPtr_IRQ::ForceDisabled()
#define ENABLE_INTERRUPTS()        SmartPtr_IRQ::ForceEnabled()
#define INTERRUPTS_ENABLED_STATE() SmartPtr_IRQ::GetState()
#define GLOBAL_LOCK_SOCKETS(x)     SmartPtr_IRQ x

#if defined(_DEBUG)
#define ASSERT_IRQ_MUST_BE_OFF()   ASSERT(!SmartPtr_IRQ::GetState())
#define ASSERT_IRQ_MUST_BE_ON()    ASSERT( SmartPtr_IRQ::GetState())
#else
#define ASSERT_IRQ_MUST_BE_OFF()
#define ASSERT_IRQ_MUST_BE_ON()
#endif


//
// macros
//
/////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////
//
// global functions
//

//
// global functions
//
/////////////////////////////////////////////////////////

#include <processor_selector.h>

#endif // PLATFORM_ARM_CQFM3DUINO
//
// drivers
/////////////////////////////////////////////////////////

#endif // _PLATFORM_CQFM3DUINO_SELECTOR_H_
